package com.yq.cp.mapper.permission;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yq.cp.entity.common.PageVo;
import com.yq.cp.entity.permission.User;
import com.yq.cp.entity.permission.dto.UserDto;
import com.yq.cp.entity.permission.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zh
 * @since 2022-09-21
 */
public interface UserMapper extends BaseMapper<User> {

    IPage<UserDto> page(IPage<UserDto> iPage, @Param("u") UserVo userVo);
    IPage<UserDto> pageFs(IPage<UserDto> iPage, @Param("u") UserVo userVo);
    IPage<UserDto> pageGz(IPage<UserDto> iPage, @Param("u") UserVo userVo);

    List<Long> byCompanyId(Long id);
    List<Long> cxzxIds();

    @Select("select * from  t_user where id=#{id}")
    User byId(@Param("id") Long id);

    List<Map> userData(@Param("val") PageVo val);

    List<Map> userRegionData(@Param("val") PageVo val);

    Page<User> structureList(@Param("page") Page<User> page, @Param("vo")PageVo vo);
    @Select("SELECT COUNT(u.id) FROM t_user u LEFT JOIN t_position p ON u.position_id=p.id WHERE u.site_id=#{nyzId}   AND p.head_or_ordinary=1 AND p.is_delete=0 AND u.is_delete=0 AND u.id=#{userId}")
    Long cxsfwyg(@Param("nyzId") Long nyzId,@Param("userId") Long userId);
    @Select("SELECT COUNT(u.id) FROM t_user u LEFT JOIN t_position p ON u.position_id=p.id WHERE u.site_id=#{nyzId}   AND p.head_or_ordinary=0 AND p.is_delete=0 AND u.is_delete=0 AND u.id=#{userId}")
    Long cxsfwfzr(@Param("nyzId") Long nyzId,@Param("userId") Long userId);
    @Select("SELECT COUNT(u.id) FROM t_user u LEFT JOIN t_organizational_structure os ON os.id=u.structure_id AND os.type=6 WHERE u.is_delete=0 AND os.is_delete=0 AND u.structure_id=#{nyzId} AND u.id=#{userId}")
    Long cxsfwzz(@Param("nyzId") Long nyzId,@Param("userId") Long userId);
    @Select("SELECT COUNT(u.id) FROM t_user u LEFT JOIN t_organizational_structure os ON os.id=u.structure_id AND os.type=5 WHERE u.is_delete=0 AND os.is_delete=0 AND u.structure_id=#{nyzId} AND u.id=#{userId}")
    Long cxsfwqx(@Param("nyzId") Long nyzId,@Param("userId") Long userId);

    @Select("SELECT * FROM t_user u WHERE u.is_delete=0 AND  u.id=#{userId}")
    User cxuser(@Param("userId") Long userId);
}
